﻿using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;

namespace Adams.Admin.Presentation.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class ClassifiedsController : Controller
    {
        [AppendLayoutViewModel]
        public ActionResult Index()
        {
            var model = Business.Classifieds.Index.PageLoad();
            ViewBag.Message = Request["msg"];
            return View(model);
        }

        public JsonResult GridLoad(DataTransfer.GridLoadInput gridinput)
        {
            var model = Business.Classifieds.Index.GridLoad(gridinput);
            return Json(model);
        }

        [AppendLayoutViewModel]
        public ActionResult Create(int id)
        {
            var model = Business.Classifieds.Create.PageLoad(id);
            return View(model);
        }

        public JsonResult GetCategoriesByType(string typeId)
        {
            var model = Business.Classifieds.Create.GetCategoriesByType(typeId.ToInt());
            return Json(model);
        }

        public JsonResult Save(Adams.Admin.DataTransfer.Classifieds.Create.FormInput input)
        {
            var model = Business.Classifieds.Create.Save(input);
            return Json(model);
        }

        public RedirectResult Delete(int id)
        {
            Business.Classifieds.Index.Delete(id);
            var model = new { Success = true };
            return Redirect("/Classifieds?msg=2");
        }

        [AppendLayoutViewModel]
        public ActionResult Pending()
        {
            var model = Business.Classifieds.Pending.PageLoad();
            return View(model);
        }

        public JsonResult UpdateStatus(Adams.Admin.DataTransfer.Classifieds.Pending.UpdateStatusInput input)
        {
            Business.Classifieds.Pending.UpdateStatus(input);
            var model = new { Success = true, PostingID = input.PostingID };
            return Json(model);
        }

        public JsonResult PendingDelete(int id)
        {
            Business.Classifieds.Index.Delete(id);
            var model = new { Success = true, PostingID = id };
            return Json(model);
        }

        [AppendLayoutViewModel]
        public ActionResult Categories()
        {
            var model = Business.Classifieds.Categories.PageLoad();
            return View(model);
        }

        public JsonResult GetType(Adams.Admin.DataTransfer.Classifieds.Categories.GetTypeInput input)
        {
            var model = Business.Classifieds.Categories.GetType(input);
            return Json(model);
        }

        public JsonResult GetCategory(Adams.Admin.DataTransfer.Classifieds.Categories.GetCategoryInput input)
        {
            var model = Business.Classifieds.Categories.GetCategory(input);
            return Json(model);
        }

        public JsonResult SaveType(DataTransfer.Classifieds.Categories.TypeFormInput input)
        {
            var model = Business.Classifieds.Categories.SaveType(input);
            return Json(model);
        }

        public JsonResult SaveCategory(DataTransfer.Classifieds.Categories.CategoryFormInput input)
        {
            var model = Business.Classifieds.Categories.SaveCategory(input);
            return Json(model);
        }

        public JsonResult DeleteType(int TypeID)
        {
            Business.Classifieds.Categories.DeleteType(TypeID);
            return Json(new { status = true });
        }

        public JsonResult DeleteCategory(int CategoryID)
        {
            Business.Classifieds.Categories.DeleteCategory(CategoryID);
            return Json(new { status = true });
        }
    }
}
